package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserGroupBean;
import com.koron.css2.clientCenter.mapper.UserGroupMapper;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 批量删除用户组
 * @author 张涛
 * @date 2022/3/9
 */
public class UserGroupBatchDelete implements ServerInterface{

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<String> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "批量删除成功", String.class);
		try {
			UserGroupBean bean = JsonUtils.objectToPojo(req.getData(), UserGroupBean.class);
			UserGroupMapper mapper = factory.getMapper(UserGroupMapper.class);
			UserInfoMapper uiMapper = factory.getMapper(UserInfoMapper.class);
			for (String userGroupNo : bean.getUserGroupNoList()) {
				mapper.delete(userGroupNo);
				uiMapper.updateUserGroupNoNull(userGroupNo);
			}
			return info;
		} catch (Exception e) {
			// TODO: handle exception
			logger.error("用户组批量删除失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "批量删除失败", null);
		}
	}

}
